package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.dto.SearchFilterDTO;
import com.hmall.common.vo.FilterParamVo;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    /**
     * 分页查询商品列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    public PageDTO<Item> listPage(Long page, Long size){
        return itemService.listPage(page,size);
    }

    /**
     * 根据id搜索商品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Item getById(@PathVariable Long id){
        return itemService.getById(id);
    }

    /**
     * 新增商品
     * @param item
     */
    @PostMapping
    public void save(@RequestBody Item item){
        itemService.save(item);
    }

    /**
     * 更新商品状态
     * @param id
     * @param status
     */
    @PutMapping("/status/{id}/{status}")
    public void updateStatus(@PathVariable Long id,@PathVariable Integer status){
        itemService.updateStatusById(id,status);
    }

    /**
     * 修改商品
     * @param item
     */
    @PutMapping
    public void update(@RequestBody Item item){
        itemService.updateById(item);
    }

    /**
     * 根据id删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id){
        itemService.removeById(id);
    }

    @PostMapping("/search")
    public SearchFilterDTO search(@RequestBody FilterParamVo filterParamVo){
        return itemService.searchFilter(filterParamVo);
    }

    /**
     * 客户端条件查询
     * @param filterParamVo
     * @return
     */
    @PostMapping("/search/list")
    PageDTO<Item> searchListItem(@RequestBody FilterParamVo filterParamVo){
        return itemService.searchListItem(filterParamVo);
    }
}
